﻿/*
#------------------------------------------------------------------------------
#-- Program Name:	[dbo].[spInsertLogEntry]
#-- Purpose:		Writes a log entry to the SQL Server Log File
#--	Last Update:	06/01/2012
#--					For a complete history - please review comments in SVN
#------------------------------------------------------------------------------
*/
CREATE PROCEDURE [dbo].[spInsertLogEntry]
(
	@program_name	sysname, 
	@message		nvarchar(2000)
)
WITH EXECUTE AS OWNER
AS

SET NOCOUNT ON

--- Parameter validation
IF @program_name IS NULL AND @message IS NULL
	return

--- Declare Local Variables
DECLARE @msg nvarchar(4000)

--- Set a default value for @program_name
IF LTRIM(RTRIM(ISNULL(@program_name, ''))) = ''
	SELECT	@program_name = 'Command Line'

--- Set a default value for @message
IF LTRIM(RTRIM(ISNULL(@program_name, ''))) = ''
	SELECT	@message = 'No message passed in'

--- Define the message to log
SELECT	@msg = '[' + @program_name + '] ' + ISNULL(@message, '')

--- Log the message
RAISERROR(@msg, 0, 1) WITH LOG

SET NOCOUNT OFF